/**
 * Created by Administrator on 2016/6/22.
 */
$(function(){

    var startdatechat = $.cookie("startdatechat");
    var enddatechat = $.cookie("enddatechat");
    if (startdatechat && enddatechat){
        $('#clan_start').val(dataChangeForUse(startdatechat)).attr('data-time',startdatechat);
        $('#clan_end').val(dataChangeForUse(enddatechat)).attr('data-time',enddatechat);
    }

    jsonPicture = JSON.parse($("#_json_picture").attr('content'));
    //申请预定固定
    // checkWindowHeight();
    // hidefixedBox.hideBox();

    //放大图模块 点击小图片切换图片效果
    $('.smallimglist').on('click','img',function(){
        var actIndex = $('.smallimglist').find('img.action').index();
        var nextIndex = $(this).index();
        maxchangeBigImg(nextIndex);
        var tab = $('.smallimglist').find('img');
        tab.eq(actIndex).removeClass('action');
        tab.eq(nextIndex).addClass('action');
    });

    //点击图片，显示放大
    $('.normalimgbox').on('click','img',function(){
        $('.biger-shadow').show().css('height',$('body').height());
        $('body').css({'overflow':'hidden','padding-right':getScrollbarWidth()});


        var actIndex = $('.smallimglist').find('img.action').index();
        var nextIndex = parseInt($('.img-show').attr('data-index'));
        maxchangeBigImg(nextIndex);
        var tab = $('.smallimglist').find('img');
        tab.eq(actIndex).removeClass('action');
        tab.eq(nextIndex).addClass('action');


        var smallimglistwidth=$('.smallimglist').width();
        var divsor=6;
        if(parseInt(smallimglistwidth)==1070)
            divsor=7;
        var left=0;
        var lengthstr= tab.length;
        if(nextIndex<=(lengthstr-divsor)){
            left=-((nextIndex)*154);
        }
        else{
            left=-((lengthstr-divsor)*154);
        }
        if(tab.length<=divsor)
            left=0;

        $('.smallimglist .smalllistul').stop(true).animate({left: left+"px"}, 10);




        $('.biger-display').show();
        var $biglargeimg=$('#biger-largeimg');
        //$('.indexbox').width($biglargeimg.width()).css('margin-left',$biglargeimg.css('marginLeft'));

        var $description = $('.descriptionbox .description').eq(0);//描述操作
        var descripthtml=$description.html();
        if(descripthtml){
            $description.show().siblings().hide();
        }else{
            $description.siblings().hide();
        }
    });

    //放大图片模块 点击关闭按钮
    $('.big-img-close').on('click',function(){
        $('.biger-display').hide();

        $('.biger-shadow').hide();
        $('body').css({'overflow':'auto','padding-right':'0'});
    });


    var width = $(document).width();
    if(width<=768){
        $('.detail-img-box').remove();
    }else{
        $('.house-visual').remove();
    }
    var height = width*2/3;
    $('.pageType2 .main-image').css('height',height+'px');
    $('.pageType2 .main-image ul li img').css('height',height+'px');
    $(".main-image").touchSlider({
        flexible : true,
        speed : 200,
        counter : function (e){}
    });

    DetailPageApp.init();

    var opt={
        input:$('#detial-owner .defineselectinput'),
        box:$('#detial-owner .defineselectbox')
    }
    defineSelect.init(opt,analyzeOrder);

    //设置货币
    var currency_symbol = '￥';
    setCurrencySymbol();

    $('#book_it_buttons').click(function(){

        //登陆状态未完善资料检测
        var isJump = addListenNotPerfect();
        if(!isJump){
            return;
        }
        var checkin = $('.checkins').val();
        var checkout = $('.checkouts').val();

        if(!$.cookie('yyoh') || !$.cookie('id')){
            // 去登录
            loginLink_Header();
            return;
        }else if(checkin == '' || checkout == ''){
            $('#book_it_disabled_message').html('<span>' + $ .i18n.prop('38a0a29717bf5c7974cbd3c8d22e365b') + '</span>').parent().show();
            $('#book_it_disabled_message').removeClass('hide');
            return;
        }


        //进行拦截
        var check = $('#book_it_disabled_message').attr('class');
        if(check.indexOf('hide')<0){
            //$( "#book_it_disabled_message").children('span').effect( "bounce","slow");
        }else{

            var number_of_guest = $('.defineselectinput').attr('numvalue');
            var houseId = $('#houseId').val();
            var param = {
                yyoh: $.cookie("yyoh"),
                userId: $.cookie("id"),
                attrList: ["certPhotoPn","certStatus"]
            };
            var value = JSON.stringify(param);

            // 首先判断一下是否是闪定,是否还有房,没有的话给出提示,取消预订;
            var flashOrderHouseFlag = $('[name=flashOrderHouseFlag]').val();
            if(flashOrderHouseFlag == 1) {
                var params = {
                    houseId: houseId,
                    startDate: dataChangeForUse(checkin),
                    endDate: dataChangeForUse(checkout),
                    peopleNum:number_of_guest,

                }
                checkXZStockQueryHouse(params,function(data) {
                    if(data.status.status_code == 0){
                        treatData('userInfo/getUserInfoById',value,function (data) {
                            if(data.status.status_code == 0){
                                var certStatus = data.result.user.certStatus;
                                $.cookie('certStatus',certStatus,{expire:10,path:'/'});
                                if($('input[name=veriCertStatus]').val() == 1 && (certStatus == 0 || certStatus == 3)){ //是国内房源并且身份认证未审核或审核失败
                                    pcAlert(1,$.i18n.prop('b016fdcf82b7a1c2860ce2555169a070'),$.i18n.prop('ac59d6185523860a069a87e234083637'),'',function () {
                                        window.location.href = '/user/p_certify?history=/redPacket/p_consumption?checkin='+checkin+'&checkout='+checkout+'&number_of_guests='+number_of_guest+'&houseid='+houseId;
                                    },$.i18n.prop('0bb693fe216f2459916db6572698a21b'),$.i18n.prop('96961d3da35c95e72c0d9eed9719aea0'));
                                }else{
                                    window.location.href='/redPacket/p_consumption?checkin='+checkin+'&checkout='+checkout+'&number_of_guests='+number_of_guest+'&houseid='+houseId;
                                }
                            }
                        });
                    } else {
                        var levelName3 = ($('input[name=levelName3]').val() == $.i18n.prop('eb07a031a3b13a882336e853e5ec2a92'))?'':$('input[name=levelName3]').val();
                        var levelName2 = ($('input[name=levelName3]').val() == $.i18n.prop('eb07a031a3b13a882336e853e5ec2a92'))?'':$('input[name=levelName2]').val();
                        var levelName1 = ($('input[name=levelName3]').val() == $.i18n.prop('eb07a031a3b13a882336e853e5ec2a92'))?'':$('input[name=levelName1]').val();
                        var levelName = levelName3 || levelName2 || levelName1;
                        console.log($.i18n.prop('9b433f91ed1ae06f94f55eec4ca2ce53'));
                        pcAlert(1,$.i18n.prop('0b3541dfd747323c153d0326611e9d23'),$.i18n.prop('9b433f91ed1ae06f94f55eec4ca2ce53'),'',function () {
                            window.location.href = levelName?'/kw/'+levelName+'/?startDate='+checkin+'&endDate='+checkout:'/';
                        },$.i18n.prop('0bb693fe216f2459916db6572698a21b'),$.i18n.prop('386dbd641d2c1599bab2c2c68c1a28a1'));
                    }
                });
            } else {
                treatData('userInfo/getUserInfoById',value,function (data) {
                    if(data.status.status_code == 0){
                        var certStatus = data.result.user.certStatus;
                        $.cookie('certStatus',certStatus,{expire:10,path:'/'});
                        if($('input[name=veriCertStatus]').val() == 1 && (certStatus == 0 || certStatus == 3)){ //是国内房源并且身份认证未审核或审核失败
                            pcAlert(1,$.i18n.prop('b016fdcf82b7a1c2860ce2555169a070'),$.i18n.prop('ac59d6185523860a069a87e234083637'),'',function () {
                                window.location.href = '/user/p_certify?history=/redPacket/p_consumption?checkin='+checkin+'&checkout='+checkout+'&number_of_guests='+number_of_guest+'&houseid='+houseId;
                            },$.i18n.prop('0bb693fe216f2459916db6572698a21b'),$.i18n.prop('96961d3da35c95e72c0d9eed9719aea0'));
                        }else{
                            window.location.href='/redPacket/p_consumption?checkin='+checkin+'&checkout='+checkout+'&number_of_guests='+number_of_guest+'&houseid='+houseId;
                        }
                    }
                });
            }
        }

    });

    //点击弹出地图
    $('.address-click').click(function(){
        // var longitude=$('[name=longitude]').val();
        // var latitude=$('[name=latitude]').val();
        //
        // $('.room_map').children('.addressForMap').attr('src','/room/p_mapWeb?longitude='+longitude+'&latitude='+latitude +'&isPosi=ok');

        var houseId = $('[name=houseId]').val();

        $('.room_map').children('.addressForMap').attr('src','/room/p_mapWeb?houseid='+houseId+'&type=google');

        if($('body').width() > 768){
            $('.div_overlay').show();
            var wMap = $('.room_map').width();
            wMap = wMap/2;
            $('.room_map').css('margin-left','-'+wMap+'px');
        }else{
            var left = ($('body').width() - 40)/2;
            $('.room_map .close').css('right',left+'px');
        }
        $('body').css('overflow', 'hidden');
        $('.apply-for-room').hide();//申请预订按钮隐藏
        $('.apply-for-room').removeClass('visible-xs-block');
        $('.room_map').show();
    });
    //点击遮罩层，隐藏头像上传
    $('.div_overlay,.room_map .close').click(function(){
        $('.div_overlay').hide();
        $('.room_map').hide();
        $('.apply-for-room').show();//申请预订按钮显示
        $('.apply-for-room').addClass('visible-xs-block');
        $('body').css('overflow','auto');
    });
    //点击新加隐藏对应iframe地图的按钮弹出地图a
    $('.outerIconList a').click(function(){
        var longitude=$('[name=longitude]').val();
        var latitude=$('[name=latitude]').val();

        $('.room_map').children('.addressForMap').attr('src','/room/p_mapWeb?houseid='+houseId+'&isPosi=ok'+'&currCheck='+ $(this).index());
        if($('body').width() > 768){
            $('.div_overlay').show();
            var wMap = $('.room_map').width();
            wMap = wMap/2;
            $('.room_map').css('margin-left','-'+wMap+'px');
        }else{
            var left = ($('body').width() - 40)/2;
            $('.room_map .close').css('right',left+'px');
        }
        $('body').css('overflow', 'hidden');
        $('.apply-for-room').hide();//申请预订按钮隐藏
        $('.apply-for-room').removeClass('visible-xs-block');
        $('.room_map').show();
    });
    //点击遮罩层，隐藏头像上传
    $('.div_overlay,.room_map .close').click(function(){
        $('.div_overlay').hide();
        $('.room_map').hide();
        $('.apply-for-room').show();//申请预订按钮显示
        $('.apply-for-room').addClass('visible-xs-block');
        $('body').css('overflow','auto');
    });

    //收藏和取消收藏功能
    $('.attention').click(function(){
        //如果房源没有被收藏过，直接调用ajax收藏房源
        if($.cookie("yyoh") && $.cookie("id")){
            var ownerId = $('input[name=ownerId]').attr('value');
            if(ownerId == $.cookie("id")){
                alert($.i18n.prop('d65c5606aa2c44691ba77c68f5f88021'));
            }else{
                //登陆状态未完善资料检测
                var isJump = addListenNotPerfect();
                if(!isJump){
                    return;
                }
                var param = {};
                param.yyoh = $.cookie("yyoh");
                param.userId = $.cookie("id");
                param.houseId = $('#houseId').attr('value');
                var value = JSON.stringify(param);
                var status = $(this).attr('data-status');
                if(status == 0){
                    //加入收藏
                    treatData('collect/addCollect',value,function(data){
                        if(data.status.status_code == 0){
                            $('.attention').attr('data-status',1);
                            $('.attention').addClass('already');
                        }
                    }, "json");
                }else{
                    //取消收藏
                    treatData('collect/cancelCollect',value,function(data){
                        if(data.status.status_code == 0){
                            $('.attention').attr('data-status',0);
                            $('.attention').removeClass('already');
                        }
                    }, "json");
                }
            }
        }else{
            var url = window.location.pathname;
            window.location.href = "/login/p_login?history="+url;
        }
    });

    //判断房屋描述的高度，进行折叠操作
    var summaryHei = $('.housepre').height();
    if(summaryHei >= 388){
        $('.summary').children('.data-conceal').removeClass('hide');

        $('.summary').next('.show-all').removeClass('hide');
    }
    $('.housedescripe .show-all').click(function(){
        var $this=$(this);
        if($this.hasClass('Allready'))
        {
            $this.prev('.summary').children('.data-conceal').removeClass('hide');
            $this.html($.i18n.prop('27fdfd86902a9d57c600a63eeedce74e') + '<span class="downward"></span>').removeClass('Allready');
            $this.prev('.summary').css('max-height','390px');
        }
        else {
            $this.html($.i18n.prop('2843c05c25d88879b7b6e84439c2a04e') + '<span class="upward"></span>').addClass('Allready');
            $this.prev('.summary').css('max-height','none');
            $this.prev('.summary').children('.data-conceal').addClass('hide');
        }

    });

//接送机展开
    $('.shuttleinfobox .show-all').click(function(){
        var $this=$(this);
        if($this.hasClass('Allready'))
        {
            $this.html($.i18n.prop('27fdfd86902a9d57c600a63eeedce74e') + '<span class="downward"></span>').removeClass('Allready');
            $('.shuttleinfo').slideUp();

        }
        else {

            $this.html($.i18n.prop('2843c05c25d88879b7b6e84439c2a04e') + '<span class="upward"></span>').addClass('Allready');
            $('.shuttleinfo').slideDown();
        }

    });
    //展开房东评价房客的信息
    $('.comment').on('click','.comment-open',function(){
        $(this).next('.comment-reply').slideDown();
        $(this).slideUp()
    });

    //根据配套设置字段设置配套设施
    setAmenitiesForHouse();
    //详情页面图片切换效果
//                            detailImgChange();
    //将首张图片进行调整大小
    if($(window).width() > 750){
        changeBigImg(0);

        //评论点击查看大图          --20160125
//                                var obj =  $('.seeBigerPic');
//                                if(obj != undefined){
//                                   obj.seeBigerPic();
//                                }
        //评论点击查看大图          --20160125
    };
    //点击小图片切换图片效果
    $('.img-list-box').children('.change-box-1').children('img').click(function(){
        var actIndex = $('.img-list-box .change-box-1').children('img.action').index();
        var nextIndex = $(this).index();
        changeBigImg(nextIndex);
        var tab = $('.img-list-box .change-box-1').children('img');
        tab.eq(actIndex).removeClass('action');
        tab.eq(nextIndex).addClass('action');
    });
    //切换入住人数，进行订单分析
    $('#number_of_guest').change(function(){analyzeOrder();});
    //如果登陆情况下就验证是否收藏
    checkIsCollectForDetail();
    //查询评论
    getCommentList(true);

    //日历控件
    var $objDom=null;
    $('#detial-owner [calender-input="true"]').on('click',function(){

        var $this=$(this),$checkins=$('.checkins'),$checkouts=$('.checkouts');
        var datatime= $this.attr('data-time')?$this.attr('data-time'):$checkins.attr('data-time');
        $this.attr('clickActive','1');
        if(datatime)
            $objDom= $this;
        else{
            $objDom=$checkins;
            $checkins.attr('clickActive','1');
            $this.attr('clickActive','0');
        }

        var $calender = $('.calendar');
        if($calender.length==0)
        {
            $('.canlenderbox').append('<div class="calendar"></div>');
            $calender = $('.calendar');
        }
        // 确定日历定位
        var parentoffsetleft=$objDom.parents('.owner-box').offset().left,
            inputleft=$objDom.offset().left,
            termalleft = inputleft-parentoffsetleft;

        var windowwidth=$(window).width(),
            calendarwidth = $calender.outerWidth();
        if(inputleft+calendarwidth>windowwidth-10)
        {
            termalleft-=(inputleft+calendarwidth-windowwidth+10);
        }
        $calender
            .css({'top':140,'left':termalleft})
            .removeAttr('inOrOut oldMonth endMonth').empty();

        var settings={
            type       : 'details',
            startMonth:$checkins.attr('data-time')?$checkins.attr('data-time'):'',
            endMonth:$checkouts.attr('data-time')?$checkouts.attr('data-time'):'',

            invalidDate:$('[name=invalidDate]').val(),
            invalidChooseDate:$('[name=invalidChooseDate]').val(),
            minNights:$('[name=minNights]').val(),


            dynamicPrice:$('[name=dynamicPrice]').val(),
            hasWeekendPrice: $('[name=hasWeekendPrice]').val(),
            WeekendPrice:$('[name=weekendPrice]').val(),
            PricePerNight:$('[name=price_amount_num]').val(),
            houseCalendarPrice:$('[name=houseCalendarPrice]').val(),
            currency:currency_symbol,
            calMonthlength: $('[name=calMonthlength]').val() || 12,
	        unknownDateStr: $('[name=unknownDateStr]').val(),

            callback  :CalendarBack
        };
        if($('[exaggerFlag=1]').length==0)
        {
            settings.addLisener=true;
            $this.attr('exaggerFlag','1');
        }


        if($this.hasClass('checkouts') && datatime)//选择退房日期(没有选择入住日期之前不能选择退房日期)
        {
            settings.startMonth=$checkins.attr('data-time');
            settings.endMonth=$this.attr('data-time');
            settings.inOrOut=false;
        }
        $calender.appCalendar(settings);

    });

    $(window).resize(function () {
        if($('.calendar')&&$('.calendar').is(':visible')){
            var calender = $('.calendar');
            var calendarLeft = calender.offset().left,
                calendarWidth = calender.outerWidth(),
                windowWidth = $(window).width();
            if(calendarLeft+calendarWidth>windowWidth-10){
                calender.css('left',$objDom.offset().left-$('.owner-box').offset().left-(calendarLeft+calendarWidth-windowWidth+10))
            }else{
                calender.css('left',$objDom.offset().left-$('.owner-box').offset().left);
            }
        }
    });

    $('.sharebox').hover(function(event){
        if(event.type=='mouseenter'){
            $(this).find('.sharebtns').show();
        }else{
            $(this).find('.sharebtns').hide();
        }
    });

    getPosition($('.checkins'),'canlenderbox','checkinposition');
    getPosition($('.checkouts'),'canlenderbox','checkoutposition');

    //查询日历价格
    var houseId = $('input[name=houseId]').val();
    var dtd = $.Deferred()
    getHouseCalendar(houseId,function(data){//查询房子的出租状况
        try{
            if(data.status.status_code == 0)
            {
                //返回值
                //chooseDate 房东设定的特殊日期
                //price 房东自己设置的特殊日期的价格
                //hasWeekendPrice 周末价格
                //PricePerNight 每晚价格
                if(!data.result)
                    return;
                $('[name=calMonthlength]').val(data.result.calMonthlength);
                $('[name=unknownDateStr]').val(data.result.unknownDateStr);
                $('[name=dynamicPrice]').val(JSON.stringify(data.result.HouseCalendar));
                $('[name=hasWeekendPrice]').val(data.result.WeekendPrice.hasWeekendPrice);
                $('[name=weekendPrice]').val(data.result.WeekendPrice.weekendPrice);
                $('[name=houseCalendarPrice]').val(data.result.houseCalendarPrice);
                $('[name=currency]').val(data.result.currency?data.result.currency:'￥');
                dtd.resolve();
            }
        }
        catch(e){
            console.log(e);
        }
    });



    /*
     * 显示用户芝麻信用分
     */

    var num = '';
    $('.Zhima-dentity').bind({
        'mouseover':function() {
            $(this).append($('.meterParNewModel'));
            $('.meterParNewModel').show();
            if($(this).attr('data-zmDescribeLevel') != num){
                // rotateMeter($(this).attr('data-zmxyScore'),{
                //     position : 'landlord',
                //     grade : $(this).attr('data-zmxyLevel'),
                //     spanText1: $(this).attr('data-zmxyDescription'),
                //     spanText2: ''
                // });
                // 芝麻信用二维码，显示之后扫不出结果，所以暂时不做了
                // getImgByUrl(function(data) {
                //     var qrcode = new QRCode(document.getElementById("qrcodeTable"), {
                //         text: data,
                //         width: 110,
                //         height: 110,
                //         colorDark : "#000000",
                //         colorLight : "#ffffff",
                //         correctLevel : QRCode.CorrectLevel.H
                //     });
                //
                //     $('.meterParNewModel').show();
                // })

                $('.meterParNewModel').show();
            }
            num = $(this).attr('data-zmDescribeLevel');

        },
        'mouseout':function(){
            $('.meterParNewModel').hide();
        }
    });
    $('.meterParNewModel').bind({
        'mouseover':function(e) {
            $(this).show();
            return false;
        },
        'mouseout':function(){
            $(this).hide();
            return false;
        }
    });

    // 过去芝麻信用二维码链接
    function getImgByUrl(fn) {
        var ownerId = $('input[name=ownerId]').attr('value');
        var param = {
            ownerId: ownerId,
        };
        param = JSON.stringify(param);
        treatData('zmxy/mutualViewForPc',param,function (data) {
            if(data.status.status_code == 0){
                fn && fn(data.result);
            }else{

            }
        });
    }

    //根据分数显示星级
    //console.log($(".comment-star").attr("data-ComprehensiveScore"));
    var ComprehensiveScore = $(".comment-star").attr("data-ComprehensiveScore");

    if(ComprehensiveScore < 0.1){
        $(".comment-star").attr("src", "/images/details/1.png")
    }
    if(ComprehensiveScore >= 0.1 && ComprehensiveScore < 0.6){
        $(".comment-star").attr("src", "/images/details/2.png")
    }
    if(ComprehensiveScore >= 0.6 && ComprehensiveScore < 1.1){
        $(".comment-star").attr("src", "/images/details/3.png")
    }
    if(ComprehensiveScore >= 1.1 && ComprehensiveScore < 1.6){
        $(".comment-star").attr("src", "/images/details/4.png")
    }
    if(ComprehensiveScore >= 1.6 && ComprehensiveScore < 2.1){
        $(".comment-star").attr("src", "/images/details/5.png")
    }
    if(ComprehensiveScore >= 2.1 && ComprehensiveScore < 2.6){
        $(".comment-star").attr("src", "/images/details/6.png")
    }
    if(ComprehensiveScore >= 2.6 && ComprehensiveScore < 3.1){
        $(".comment-star").attr("src", "/images/details/7.png")
    }
    if(ComprehensiveScore >= 3.1 && ComprehensiveScore < 3.6){
        $(".comment-star").attr("src", "/images/details/8.png")
    }
    if(ComprehensiveScore >= 3.6 && ComprehensiveScore < 4.1){
        $(".comment-star").attr("src", "/images/details/9.png")
    }
    if(ComprehensiveScore >= 4.1 && ComprehensiveScore < 4.6){
        $(".comment-star").attr("src", "/images/details/10.png")
    }
    if(ComprehensiveScore >= 4.6){
        $(".comment-star").attr("src", "/images/details/11.png")
    }

    // 日本垃圾分类标准
    $('.JapanGarbage').click(function () {
        openInfoboxByJapanGarbage('JapanGarbageBox');
    });

    // 图片放大
    $('body').on('click','.customerCommentImg img',function () {
        var index = $(this).index();
        var children = $(this).parent().children().clone();
        children.eq(index).addClass('active');
        $('.smallImagesBox').html(children);
        var bigerImage = $('.smallImagesBox img').eq(index).attr('src').replace('_500_500_75','');
        $('.largeImagesBox img').attr('src', bigerImage);
        $('.enlargeImages').css('display','table');
        // 绑定左右箭头按钮
        bindArrow(index);
        $('body').css({'overflow':'hidden','padding-right':getScrollbarWidth()});
    });
    // 关闭放大的图片
    $('.enlargeImages').click(function (e) {
        var $etarget=$(e.target);
        if($etarget.hasClass('arrow') || $etarget.is('img')) return;
        $('.enlargeImages').hide();
        $('body').css({'overflow':'auto','padding-right':'0'});
    })

    // 获取相似房源
    var buyer_currency = $.cookie('buyer_currency');
    treatData('house/getMoreLikeHouseList','{"yyoh": "'+$.cookie("yyoh")+'","userId": "'+$.cookie("id")+'","houseId":"'+houseId+'","typeNum":"'+buyer_currency+'"}',function (data) {
        if(data.status.status_code == 0){
            var likeHouseList = data.result.likeHouseList,
                listLength = likeHouseList.length;
            if(!listLength){
                $('.similarRooms').hide();
                $('#scorllFather').find('li').eq(4).hide();
                $('#housebaseinfo').find('.all-content-style').removeClass('borderB');
            }
            var similarRooms = $('.similarRooms');

            var str = '<ul class="row imglistul" style="width:'+similarRooms.outerWidth()/3*listLength+'px">';
            for(var i=0;i<listLength;i++){
                str += '<li class="col-lg-4 col-md-4 paddingB0" style="width:'+similarRooms.outerWidth()/3+'px">'+ createHouseModule(likeHouseList[i],true) +'</li>';
            }
            str += '</ul>';
            if(listLength>3){
                str+='<div class="similarArrow" data-length="'+listLength+'">\n\
                        <span class="disabled similarArrowLeft svg-father-class2" data-direction=-1></span>\n\
                        <span class="similarArrowRight svg-father-class2" data-direction=1></span>\n\
                      </div>';
            }
            str += '<div class="clearfx"></div>';
	        similarRooms.append(str);
            setCurrencySymbol();

            $(window).resize(function () {
                $('.imglistul').css('width',similarRooms.outerWidth()/3*listLength).find('li').css('width',similarRooms.outerWidth()/3);
            });
        }else{
            $('.similarRooms').hide();
            $('#scorllFather').find('li').eq(4).hide();
        }
    });

    // 相似房源左右箭头事件
    var similarIndex = 3;
    $('body').on('click','.similarArrow span',function () {
        var $this = $(this);
        if($this.hasClass('disabled')) return;
        var len = $this.parent().data('length'),
            direction = $this.data('direction');
        similarIndex += direction;
        var imglistul = $('.imglistul'),
            liWidth = imglistul.find('li').outerWidth();
        imglistul.css('margin-left',(-1)*liWidth*(similarIndex-3)+'px');

        $('.similarArrow span').removeClass('disabled');
        if(similarIndex>=len){
            $('.similarArrow span:last-child').addClass('disabled');
        }
        if(similarIndex<=3){
            $('.similarArrow span:first-child').addClass('disabled');
        }
    });

    // 搜索带过来的日期
    var Request = new UrlSearch();
    if(Request.startDate && Request.endDate){
        var startDate = Request.startDate,endDate = Request.endDate,guestNum = Request.guest;

        // 验证日期格式（针对恶意修改url参数的验证）
        var regExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
        var error = 0;
        if(!regExp.test(startDate) || !regExp.test(endDate)){
            // $('#book_it_disabled_message').html('无效的日期格式').removeClass('hide').parent().show();
            error++;
        }else{
            var year1 = parseInt(startDate.substr(0,4)), month1 = parseInt(startDate.substr(5,7)), day1 = parseInt(startDate.substr(8));
            var year2 = parseInt(endDate.substr(0,4)), month2 = parseInt(endDate.substr(5,7)), day2 = parseInt(endDate.substr(8));
            if(day1 > getDaysInMonth(year1,month1) || day2 > getDaysInMonth(year2,month2)){
                // $('#book_it_disabled_message').html('无效的日期格式').removeClass('hide').parent().show();
                error++;
            }
        }

        // 入住日期不小于今天且入住日期小于退房日期
        if(error == 0){
            if(Date.parse(startDate)>=Date.parse(endDate) || Date.parse(startDate+' 24:00:00')<=Date.parse(new Date())){
                // $('#book_it_disabled_message').html('无效的入住日期').removeClass('hide').parent().show();
                error ++;
            }
        }

        // 最晚入住日期验证
        if (error == 0){
            var tempd1=new Date(startDate),tempd2=new Date(endDate);
            var daycount=parseInt(Math.abs(tempd2-tempd1)/1000/60/60/24);
            var minNight = parseInt($('[name=minNights]').val());
            if(daycount<minNight){
                $('#couts').val('').attr('data-time','');
                $('#clan_end').val('').attr('data-time','');
                // $('#book_it_disabled_message').html('小于最晚入住天数').removeClass('hide').parent().show();
                error ++;
            }
        }

        // 所选日期是否包括不可选日期验证
        if(error == 0){
            var start = dataChangeForUse(startDate);
            var end = dataChangeForUse(endDate);
            var invalidDate = $('input[name=invalidDate]').val() + ',' + $('input[name=invalidChooseDate]').val();
            var inteval = [start];
            for(var i=0;i<100;i++){
                var tomorrow = getTomorrow(start);
                if(tomorrow == end){
                    break;
                }
                inteval.push(tomorrow);
                start = tomorrow;
            }
            for(var j = 0; j<inteval.length;j++){
                if(invalidDate.indexOf(inteval[j])>=0){
                    // $('#book_it_disabled_message').html('存在不可选日期，请重新选择').removeClass('hide').parent().show();
                    error ++;
                    break;
                }
            }
        }

        // 入住人数
        if(guestNum){
            $('input[name=accommodateNum]').val(guestNum+$.i18n.prop('d66c0775c6096ad79a6d1302cd01ccad')).attr('numvalue',guestNum);
            $('#chan_accommodateNum').val(guestNum+$.i18n.prop('d66c0775c6096ad79a6d1302cd01ccad')).attr('numvalue',guestNum);
        }

        // 生成订单价格详情
        if(error == 0) {
            $('#cins').val(startDate).attr('data-time',dataChangeForUse(startDate));
            $('#couts').val(endDate).attr('data-time',dataChangeForUse(endDate));
            $('#clan_start').val(startDate).attr('data-time',dataChangeForUse(startDate));
            $('#clan_end').val(endDate).attr('data-time',dataChangeForUse(endDate));
            dtd.then(analyzeOrder)
        }
    }

    //翻译事件
    $('body').on('click','.translateBtn',function () {
        var _this = $(this);
	    var currentLanguage = $.i18n.prop(publicMethods.languageArr[$.cookie('language')||'zh'] || 'ba61401f60eaab451e8cd2e739aa7a03');
        var translateDisplay = $(this).parents('.translateWrap').find('.translateDisplay');
        if($(this).attr('temp-text')){//请求过接口后进行交换操作即可
            var tempText = translateDisplay.html();
	        translateDisplay.html($(this).attr('temp-text'));
	        $(this).attr('temp-text',tempText);
	        if($(this).attr('initial') == '0'){
		        $(this).attr('initial','1').html($.i18n.prop('ba61401f60eaab451e8cd2e739aa7a08')+' '+currentLanguage);
            }else{
		        $(this).attr('initial','0').html($.i18n.prop('9b5facf86f4ba96dbffdc7dd46713047'));
            }
	        return;
        }
        var subject = $(this).attr('data-subject');
	    var id = '';
        if(subject == 'HOUSE'){
	        id = $('input[name=houseId]').val();
	        // id = 20285857;
        }else if(subject == 'COMMENT'){
	        id = $(this).attr('data-id');
	        // id = 20543375;
        }
        var child = $(this).attr('data-child').split(',');
	    getTranslateContent(subject,id,child,function(data){
            if(data.status.status_code == 0){
                var str = '';
                for(var i in child){
	                if(data.result[subject+'-'+id+'-'+child[i]]){
		                str += data.result[subject+'-'+id+'-'+child[i]];
	                }
                }
	            _this.attr('initial','0').html($.i18n.prop('9b5facf86f4ba96dbffdc7dd46713047'));
	            _this.attr('temp-text',translateDisplay.html());//把原文存起来
	            translateDisplay.html(str);
            }else{
                alert(data.status.status_reason);
            }
        })
    });

    //设置货币
    function setCurrencySymbol() {
        var userId=$.trim($('[name=userId]').val());
        var ownerId=$.trim($('[name=ownerId]').val());

        var preview = $('input[name=preview]').val();
        if(preview == '1' && userId == ownerId){
            var currency_symbol_arr = JSON.parse($.cookie("currency_symbol_arr"));
            var curr = parseInt($('#buyer_currency_symbol').attr('data-currency'))-1;
            currency_symbol = currency_symbol_arr[curr].symbol;
            $('.buyer_currency_symbol').html(currency_symbol);
        }else{
            if($.cookie("currency_symbol")){
                currency_symbol = $.cookie("currency_symbol");
            }
            $('.buyer_currency_symbol').html(currency_symbol);
        }
    }

    // 放到扫码想去折扣券
    $('.erweima-tips').mouseenter(function() {
        $('.discount-coupon-tips-model').show();
    }).mouseleave(function() {
        $('.discount-coupon-tips-model').hide();
    })

});
// 获取某月的总天数
function getDaysInMonth(year,month) {
    return new Date(year,month,0).getDate();
}

// 评论图片放大后的左右箭头事件
function bindArrow(index) {
    var index = index;
    $('.enlargeImages .arrow').click(function () {
        var direction = parseInt($(this).attr('data-direction'));
        var smallImages = $('.smallImagesBox img'), len = smallImages.length;
        index = index+direction;
        if(index>=len){
            index = 0;
        }else if(index<0){
            index = len-1;
        }
        // $('.largeImagesBox img').attr('src',smallImages.eq(index).attr('src'));
        var bigerImage = $('.smallImagesBox img').eq(index).attr('src').replace('_500_500_75','');
        $('.largeImagesBox img').attr('src', bigerImage);
        smallImages.removeClass('active');
        smallImages.eq(index).addClass('active');
    })
}

var ieflag=false;
if (!!window.ActiveXObject || "ActiveXObject" in window){
    ieflag=true;
}


//评论翻页查询
function this_page_details(page){
    $('.pagination-responsive').attr('data-page',page);
    getCommentList(false);
	$('#scorllFather').children('li').eq(3).trigger('click');
}

function previous_page_details(){
    var page = parseFloat($('.pagination-responsive').attr('data-page'))-1;
    $('.pagination-responsive').attr('data-page',page);
    getCommentList(false);
	$('#scorllFather').children('li').eq(3).trigger('click');
}

function next_page_details(){
    //判断查询出来的房源数量，如果不是9个，就证明没有下一页了
    var page = parseFloat($('.pagination-responsive').attr('data-page'))+1;
    $('.pagination-responsive').attr('data-page',page);
    getCommentList(false);
	$('#scorllFather').children('li').eq(3).trigger('click');
}
//【定位
window.DetailPageApp={
    init:function(){
        this.initFixedHeader();

    },
    initFixedHeader : function(){
        var that = this;

        var detailImageBox = $('#houseiimgbox');
        var introducePart = $('#housegaikuang');//房源描述
        var mapPart = $('#housebaseinfo');//房源信息
        var rulesPart = $('#houseaddress');//房源地址
        var commentPart = $('#usercomment');//用户评价
        var similarRooms = $('#similarRooms');//相似房源

        var scrollHeaderHeight = $('#scrollHeader').height();


        $('#scorllFather').children('li').on('click',function() {
            var curPartTop = 0;
            switch($(this).index()) {
                case 0:
                    curPartTop = introducePart.offset().top;
                    break;
                case 1:
                    curPartTop = mapPart.offset().top;
                    break;
                case 2:
                    curPartTop = rulesPart.offset().top;
                    break;
                case 3:
                    curPartTop = commentPart.offset().top;
                    break;
                case 4:
                    curPartTop = similarRooms.offset().top;
                    break;
            }
            $('html,body').animate({'scrollTop':curPartTop-scrollHeaderHeight});
        });
        var otherRoomPart = $('.footer-box').offset().top;//底部
        var canlenheight=$('.canlenderbox').height();

        var footerheight=$('.footer-box').height();//底部

        //var canlenheight=398;//日历
        //var footerheight=450;//底部


        //alert(documentheight+'winh:'+$(window).height()+' canlenheight:'+canlenheight+ ' footerheight:'+footerheight);



        var callentop=$('.canlenderbox').offset().top;//日历
        $(window).scroll(function() {
            var scrollTop = $(document).scrollTop();
            var scrollBottom = $('.commentContent').offset().top + $('.commentContent').outerHeight(); //评论下方距文档顶部的距离
	        var callenheight=$('.canlenderbox').height();//日历高度
            if(scrollTop+callenheight <= scrollBottom){
                if(scrollTop>callentop)
                {
                    /*if($('#scrollHeader').css('display')=='none')
                     $('.canlenderbox').css("top",scrollTop-callentop);
                     else
                     $('.canlenderbox').css("top",scrollTop-callentop);*/
                    $('.canlenderbox').css({"position":"fixed","top":'0px'}).addClass('canlenderFixed').removeClass('canlenderUnfixed');
                }
                else
                    $('.canlenderbox').css({"position":"absolute","top":'0px'}).addClass('canlenderUnfixed').removeClass('canlenderFixed');
            }
            else
            {
                $('.canlenderbox').css({"position":"absolute","top":'0px'}).addClass('canlenderUnfixed').removeClass('canlenderFixed');
            }


            if(scrollTop >= introducePart.offset().top) {
                $('#scrollHeader').show();

            } else {

                $('#scrollHeader').hide();
            }

            if(scrollTop < introducePart.offset().top-scrollHeaderHeight-50) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(0).addClass('cur');
            } else if(scrollTop < mapPart.offset().top-scrollHeaderHeight-50) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(0).addClass('cur');
            } else if(scrollTop < rulesPart.offset().top-scrollHeaderHeight-50) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(1).addClass('cur');
            }
            else if(scrollTop < commentPart.offset().top-scrollHeaderHeight-50) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(2).addClass('cur');
            }
            else if(scrollTop >rulesPart.offset().top-scrollHeaderHeight-10) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(3).addClass('cur');
            }
            else if(scrollTop >similarRooms.offset().top-scrollHeaderHeight-10) {
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').eq(4).addClass('cur');
            }

            if (getDocumentHeights.getScrollTop()+getDocumentHeights.getClientHeight()==getDocumentHeights.getScrollHeight()){
                $('#scorllFather').find('li').removeClass('cur');
                $('#scorllFather').find('li').last().addClass('cur');

            }


        });

    }
}



////检测窗口高度
function checkWindowHeight(){
    //详情页面右侧预订窗口跟随(待优化)
    if($(window).width() > 991){
        var obj = $(".canlenderbox");

        var scrollTop = $(document).scrollTop();
        var otherRoomPart = $('.footer-box').offset().top;//底部

        var iHeight=obj.height();
        var footerHeight=$('.footer-box').height();

        var iTop = obj.offset().top;
        var iFooter = $('.footer-box').offset().top;
        var iOffset = iFooter + iTop;

        var bodyH=iFooter+footerHeight;

        window.onresize = window.onscroll = function(){
            var wiTop = (document.documentElement.scrollTop || document.body.scrollTop);
            if(wiTop >= iTop ){
                if(bodyH-wiTop>iHeight+footerHeight){
                    obj.css({"position":"fixed","top":'0px'});
                }
                else {
                    obj.css({"position":"absolute","top":'0px'});
                }

            }else{
                obj.css({"position":"absolute","top":'0px'});
            }
        }
    }
}


function CalendarBack(param){//选择日期后的回调函数
    var $checkin=$('.checkins');
    var $checkout=$('.checkouts');
    var $errorobj= $('#book_it_disabled_message');
    var flagc=0;
    $('.calendar').removeAttr('inOrOut oldMonth endMonth startmonth').empty().hide();
    if(param.info==-2)
    {
        //$errorobj.html('选择日期有误，请重新选择').removeClass('hide').parent().show();

        $('#book_it_disabled_message').attr('errortype',2);
        //$('#book_it_buttons').removeClass('marginT15');

        $('.priceList').html('');
        $('.priceList-box').addClass('hide');
        flagc++;



        if($checkin.attr('clickActive'))//日历是由入住文本框触发
        {
            $checkin.val(dataChangeForUse(param.startMonth)).attr('data-time', param.startMonth);
            $checkin.removeAttr('clickActive');
            $checkout.val('').removeAttr('data-time').click();
        }
        else
        {
            $errorobj.html($.i18n.prop('f004f9ea0db850ba847cdfd90b9b9608')).removeClass('hide').parent().slideDown();

            setTimeout(function(){$errorobj.addClass('hide').parent().slideUp()}, 2000);
        }

    }
    else if(param.info==-1)
    {
        //$errorobj.html('入住日期和退房日期小于最少入住时间').removeClass('hide').parent().show();

        $errorobj.html($.i18n.prop('2646242be7127565db0aa0ae1177f56c')).removeClass('hide').parent().slideDown();
        setTimeout(function(){$errorobj.addClass('hide').parent().slideUp()}, 2000);

        //$checkin.val(dataChangeForUse(param.startMonth)).attr('data-time', param.startMonth);
        //$('#book_it_buttons').removeClass('marginT15');
        $('.priceList').html('');
        $('.priceList-box').addClass('hide');
        $checkin.removeAttr('clickActive');
        $checkout.removeAttr('clickActive');

        $('#book_it_disabled_message').attr('errortype',2);
        flagc++;


        if($checkin.attr('clickActive'))//日历是由入住文本框触发
        {
            $checkin.val(dataChangeForUse(param.startMonth)).attr('data-time', param.startMonth);
            $checkin.removeAttr('clickActive');
            $checkout.val('').removeAttr('data-time').click();
        }
        else
        {
            $errorobj.html($.i18n.prop('f004f9ea0db850ba847cdfd90b9b9608')).removeClass('hide').parent().slideDown();

            setTimeout(function(){$errorobj.addClass('hide').parent().slideUp()}, 2000);
        }
    }
    else {
        if(!$errorobj.hasClass('hide'))
            $errorobj.html('').addClass('hide');
        var btnbook=$('#book_it_buttons');
        //if(!btnbook.hasClass('marginT15'))
        //    btnbook.addClass('marginT15');




        if(!param.startMonth &&!param.endMonth)//是清除按钮
        {
            $checkin.val('').removeAttr('data-time');
            $checkout.val('').removeAttr('data-time');
            $checkin.removeAttr('clickActive');
            $checkout.removeAttr('clickActive');

            $('.priceList').html('');
            $('.priceList-box').addClass('hide');

            $('#book_it_disabled_message').attr('errortype','');
            flagc++;

        }
        else {

            if($checkin.attr('clickActive'))//日历是由入住文本框触发
            {
                $checkin.val(dataChangeForUse(param.startMonth)).attr('data-time', param.startMonth);
                $checkin.removeAttr('clickActive');


                if(param.startMonth && !$checkout.attr('data-time'))
                    $checkout.click();
                if(parseInt($checkin.attr('data-time'))>=parseInt($checkout.attr('data-time'))){
                    $checkout.val('').removeAttr('data-time').click();
                }
                if(param.info==-1)
                    $checkout.val('').removeAttr('data-time').click();

	            if( flagc==0){
		            $('#book_it_disabled_message').attr('errortype','');
		            analyzeOrder();
	            }
            }
            else{
                $checkout.val(dataChangeForUse(param.endMonth)).attr('data-time', param.endMonth);
                $checkout.removeAttr('clickActive');
                if( flagc==0){
                    $('#book_it_disabled_message').attr('errortype','');
                    analyzeOrder();
                }

            }
        }

    }

    // 聊天内日历同步

    $('#clan_start').val($checkin.val()).attr('data-time',$checkin.attr('data-time')?$checkin.attr('data-time'):'');
    $('#clan_end').val($checkout.val()).attr('data-time',$checkout.attr('data-time')?$checkout.attr('data-time'):'');
    history.pushState('','',location.pathname+'?startDate='+$checkin.val()+'&endDate='+$checkout.val());


}



//判断是否收藏此房源
function checkIsCollectForDetail(){
    //如果登陆情况下就验证是否收藏
    if($.cookie('yyoh') && $.cookie('id')){
        var houseId = $('input[name=houseId]').val();
        var param = {
            yyoh:$.cookie('yyoh'),
            userId:$.cookie('id'),
            houseId:houseId
        };
        var value = JSON.stringify(param);
        treatData('collect/isCollectByHouseId',value,function(data,url){
            if(data.status.status_code == 0 && data.result.isCollect == 1){
                $('.attention').addClass('already')
            }
        });
    }
}

//详情图片切换效果启动
function detailImgChange(){
    var speed=3000;//循环时间
    var changeHouseImg = window.setInterval('detailImgChangeAction("next")',speed);//循环获取维度条数
    $('.detail-img-box .img-change,.detail-img-box .img-show .img-prev,.detail-img-box .img-show .img-next').hover(function(event){
        if(event.type=='mouseenter'){
            window.clearInterval(changeHouseImg);
        }else{
            changeHouseImg = window.setInterval('detailImgChangeAction("next")',speed);
        }
    });
}
//切换动作
function detailImgChangeAction(move){
    var _this = $('.detail-img-box .img-show');
    var index = parseInt(_this.attr('data-index'));
    if(move == 'prev'){
        var actionIndex = index-1;
        if(actionIndex<0){
            actionIndex = jsonPicture.length-1;
        }
        changeBigImg(actionIndex);

        // _this.children('img').attr('src',publicMethods.getHouseUrl(jsonPicture[actionIndex].url,'xxlarge',90,true));
        _this.find('.description').html(jsonPicture[actionIndex].description).parent().removeClass('hide');
        if(!jsonPicture[actionIndex].description){
	        _this.find('.descriptionbox').addClass('hide');
        }
    }else{
        var actionIndex = index+1;
        if(actionIndex>=jsonPicture.length){
            actionIndex = 0;
        }
        changeBigImg(actionIndex);
        // _this.children('img').attr('src',publicMethods.getHouseUrl(jsonPicture[actionIndex].url,'xxlarge',90,true));

        _this.find('.description').html(jsonPicture[actionIndex].description).parent().removeClass('hide');
        if(!jsonPicture[actionIndex].description)
            _this.find('.descriptionbox').addClass('hide');
    }
	_this.find('.pictureIndex').html(actionIndex+1+'/'+jsonPicture.length)
}
//切换图片的时候的根据图片大小调整图片位置
function changeBigImg(index){
    //console.log(jsonPicture[index].url);
    //console.log(publicMethods.getHouseUrl(jsonPicture[index].url,'xxlarge','',false));
    var container = $('.detail-img-box').children('.img-show');
    var w_x = container.width();
    var w_y = container.height();

    var $containerimg=container.children('img');
    if(!jsonPicture[index]){
        return;
    }
    var newurl=publicMethods.getHouseUrl(jsonPicture[index].url,'xxlarge','',true);
    if(ieflag){//如果是ie浏览器
        $containerimg.attr('src',publicMethods.pathSetting.hosueImgUrl);
        $containerimg.attr('src',newurl);
    }
    else{
        $containerimg.attr('src',"");
        $containerimg.attr('src',newurl);
    }
    var src = jsonPicture[index].url;
    var theImage = new Image();
    theImage.src = src;
    theImage.onload = function(){
        //原始宽度
        var img_width = this.width;
        //原始高度
        var img_height = this.height;
	    //变形后的宽度
	    var fu_width = w_y*img_width/img_height;
	    var fu_height = w_x*img_height/img_width;
	    //偏移量
	    var offset_x = (fu_width-w_x)/2;
	    var offset_y = (fu_height-w_y)/2;
        if((img_width/img_height) - (w_x/w_y) > 0){
            if((img_width/img_height) <= 2.1){
	            $containerimg.css({'width':'auto','height':'100%','margin-left': -offset_x,'margin-top':'0'});
            }else{
	            $containerimg.css({'width':'100%','height':'auto','margin-top': -offset_y,'margin-left':'0'});
            }

         }else if((img_width/img_height) - (w_x/w_y) < 0){
            if((img_width/img_height) >= 1){
	            $containerimg.css({'width':'100%','height':'auto','margin-top': -offset_y,'margin-left':'0'});
            }else{
	            $containerimg.css({'width':'auto','height':'100%','margin-left': -offset_x,'margin-top':'0'});
            }
        }else if((img_width/img_height) - (w_x/w_y) == 0){
            $containerimg.css({'width':'100%','height':'100%'});
        }
    };
    container.attr('data-index',index);
}
//根据配套设置字段设置配套设施
function setAmenitiesForHouse(){
    var amenities = new Array();
    amenities[0] = '<div class="details-icon icon-uniE659"></div><span class="amenity-short-title">' + $.i18n.prop('aa11c106cc10a14f77269ce7d03840cd') + '</span>';
    amenities[1] = '<div class="details-icon icon-uniE65D"></div><span class="amenity-short-title">' + $.i18n.prop('64c71f330a64cf42764026e3f66c5771') + '</span>';
    amenities[2] = '<div class="details-icon icon-uniE65A"></div><span class="amenity-short-title">' + $.i18n.prop('bbcfc51716b3b7072034ca04a510344d') + '</span>';
    amenities[3] = '<div class="details-icon icon-uniE65C"></div><span class="amenity-short-title">' + $.i18n.prop('f39b68b68c8e632d2e60c9e2d39175a5') + '</span>';
    amenities[4] = '<div class="details-icon icon-uniE65B"></div><span class="amenity-short-title">' + $.i18n.prop('0270e291b0ddecd48d05ddc05c5dc21f') + '</span>';
    amenities[5] = '<div class="details-icon icon-uniE657"></div><span class="amenity-short-title">' + $.i18n.prop('611b87df7f6e3be4df2e5cd4760d2bec') + '</span>';
    amenities[6] = '<div class="details-icon icon-uniE664"></div><span class="amenity-short-title">' + $.i18n.prop('cb25373c7f371ae8e476c3f90dd90bc2') + '</span>';
    amenities[7] = '<div class="details-icon icon-uniE660"></div><span class="amenity-short-title">' + $.i18n.prop('15d213fb494628e1f4a3527fab2d7b63') + '</span>';
    amenities[8] = '<div class="details-icon icon-uniE661"></div><span class="amenity-short-title">' + $.i18n.prop('c0607f14442721ab362005e14b7abc57') + '</span>';
    amenities[9] = '<div class="details-icon icon-uniE65E"></div><span class="amenity-short-title">' + $.i18n.prop('1735e27c7165d9c4314425b2c41c640f') + '</span>';
    amenities[10] = '<div class="details-icon icon-uniE667"></div><span class="amenity-short-title">' + $.i18n.prop('bacecc365380d6885729c360646e9862') + '</span>';
    amenities[11] = '<div class="details-icon icon-uniE682"></div><span class="amenity-short-title">WiFi</span>';
    amenities[12] = '<div class="details-icon icon-uniE65F"></div><span class="amenity-short-title">' + $.i18n.prop('f51a004cc8a5c228bfedfb5cbe6f9cf4') + '</span>';
    amenities[13] = '<div class="details-icon icon-uniE683"></div><span class="amenity-short-title">' + $.i18n.prop('c9a1ba0ec71f22222ff8d58c84bf451c') + '</span>';
    amenities[14] = '<div class="details-icon icon-uniE663"></div><span class="amenity-short-title">' + $.i18n.prop('ff14e0adbc7efe4a091cce9d16df9875') + '</span>';
    amenities[15] = '<div class="details-icon icon-uniE665"></div><span class="amenity-short-title">' + $.i18n.prop('59cb99b69baea6e42abbe9f82ba40fa1') + '</span>';
    amenities[16] = '<div class="details-icon icon-uniE66B"></div><span class="amenity-short-title">' + $.i18n.prop('d9f6a112bd1bf4ebc464c452bea78e7f') + '</span>';
    amenities[17] = '<div class="details-icon icon-uniE67C"></div><span class="amenity-short-title">' + $.i18n.prop('b6f54d94ff88eb01653fd963300bd37f') + '</span>';
    amenities[18] = '<div class="details-icon icon-uniE66D"></div><span class="amenity-short-title">' + $.i18n.prop('47bb9b0719af4ee6cf10adef34aa9812') + '</span>';
    amenities[19] = '<div class="details-icon icon-uniE675"></div><span class="amenity-short-title">' + $.i18n.prop('9b73c05c4fbe3bbfbc79143c1df5d08e') + '</span>';
    amenities[20] = '<div class="details-icon icon-uniE66A"></div><span class="amenity-short-title">' + $.i18n.prop('b2812aadad87bbb73ff635b986bc2a62') + '</span>';
    amenities[21] = '<div class="details-icon icon-uniE677"></div><span class="amenity-short-title">' + $.i18n.prop('1474062c67386ef23ac02647da51ec8a') + '</span>';
    amenities[22] = '<div class="details-icon icon-uniE670"></div><span class="amenity-short-title">' + $.i18n.prop('c9c3b9ed0154e2e0eead5c8c0733d838') + '</span>';
    amenities[23] = '<div class="details-icon icon-uniE679"></div><span class="amenity-short-title">' + $.i18n.prop('f1252f803cec025da446933e7fe53dc4') + '</span>';
    amenities[24] = '<div class="details-icon icon-uniE67D"></div><span class="amenity-short-title">' + $.i18n.prop('053a3293e6494f173a6ff4157dcc873f') + '</span>';
    amenities[25] = '<div class="details-icon icon-uniE66E"></div><span class="amenity-short-title">' + $.i18n.prop('f63eb8c9627ef92310fc9885decf8d6d') + '</span>';
    amenities[26] = '<div class="details-icon icon-uniE66F"></div><span class="amenity-short-title">' + $.i18n.prop('ef8ba7a0bdc2645b0b8aed9db59ea86e') + '</span>';
    amenities[27] = '<div class="details-icon icon-uniE672"></div><span class="amenity-short-title">' + $.i18n.prop('a181830a3e83afa3bd0607841fd9f442') + '</span>';
    amenities[28] = '<div class="details-icon icon-uniE678"></div><span class="amenity-short-title">' + $.i18n.prop('0b0ac6816e02dcf011aba33761e2985e') + '</span>';
    amenities[29] = '<div class="details-icon icon-uniE67A"></div><span class="amenity-short-title">' + $.i18n.prop('404e6e6961aacbb38dce038ebafbc95d') + '</span>';
    amenities[30] = '<div class="details-icon icon-uniE67B"></div><span class="amenity-short-title">' + $.i18n.prop('431070dc40e0c051a301aadb1ae7f0c2') + '</span>';
    amenities[31] = '<div class="details-icon icon-uniE66C"></div><span class="amenity-short-title">' + $.i18n.prop('7141a7016be3cb778eee867f1b5fcdd4') + '</span>';
    amenities[32] = '<div class="details-icon icon-uniE671"></div><span class="amenity-short-title">' + $.i18n.prop('a4de350854944416600e5d1b6d90c730') + '</span>';
    amenities[33] = '<div class="details-icon icon-uniE85d"></div><span class="amenity-short-title">' + $.i18n.prop('fd2a1636a16444814113b2e3279af87d') + '</span>';
    amenities[34] = '<div class="details-icon icon-uniE859"></div><span class="amenity-short-title">' + $.i18n.prop('25627c666b080dc182ec995a523604b5') + '</span>';
    amenities[35] = '<div class="details-icon icon-uniE85e"></div><span class="amenity-short-title">' + $.i18n.prop('b112330c5eae6740a59b7f0761b9bd6d') + '</span>';
    amenities[36] = '<div class="details-icon icon-uniE85c"></div><span class="amenity-short-title">' + $.i18n.prop('d50ed912e12b8390cf896955328df643') + '</span>';
    amenities[37] = '<div class="details-icon icon-uniE856"></div><span class="amenity-short-title">' + $.i18n.prop('07efc94617d022b9f41f5b64aa947fc8') + '</span>';
    amenities[38] = '<div class="details-icon icon-uniE857"></div><span class="amenity-short-title">' + $.i18n.prop('766152a15d86f061ef689ccfe800937e') + '</span>';
    amenities[39] = '<div class="details-icon icon-uniE85a"></div><span class="amenity-short-title">' + $.i18n.prop('af2c940c0b2446921c5d2f7d2a200e58') + '</span>';
    amenities[40] = '<div class="details-icon icon-uniE858"></div><span class="amenity-short-title">' + $.i18n.prop('48add2b2f47fb6c7d9a357b6a24941e9') + '</span>';
    amenities[41] = '<div class="details-icon icon-uniE855"></div><span class="amenity-short-title">' + $.i18n.prop('d9b14cdbe4459389518e2a47d631f4e6') + '</span>';
    amenities[42] = '<div class="details-icon icon-uniE854"></div><span class="amenity-short-title">' + $.i18n.prop('a9985f1dbacf2281ce4f84cd5c469e38') + '</span>';
    amenities[43] = '<div class="details-icon icon-uniE85b"></div><span class="amenity-short-title">' + $.i18n.prop('da869f533eb871cf20d8fc231f4a5bef') + '</span>';
    /* 将查询到的数据写入页面中 */
    var amenitiesValue = $('#amenities').attr('value');
    if(amenitiesValue){
        var array = new Array();
        array = amenitiesValue.split(',');
        var k = 0;//记录先显示的便利设施数目
        var str = '';
        for(var i=0;i< 44;i++){
            if(in_array(array,i.toString())){
                k++;
                str += '<div class="col-lg-3 col-md-4 padding0"><div class="row-space-1 row-amenities">'+amenities[i]+'</div></div>';
            }else{
                str += '<div class="col-lg-3 col-md-4 padding0"><div class="row-space-1 row-amenities disable">'+amenities[i]+'</div></div>';
            }
        }
        $('.amenities-box').html(str);
    } else{
        $('.amenities-box').append($.i18n.prop('eb07a031a3b13a882336e853e5ec2a92'));
    }
}


//评论查找
function getCommentList(refresh){
    var param = {};
    param.houseId = $('#houseId').attr('value');
    var page = $('.pagination-responsive').attr('data-page');
    var range = {};
    range.pageSize = 10;
    range.page = page - 1;
    param.range = range;
    var value = JSON.stringify(param);
    treatData('comment/getCommentListByHouseId',value,function(data,url){
        if(data.status.status_code == 0){
            var str = '';
            var faceUrl = $('.owner-head').attr('data-faceUrl');
            var ownernickname=$('#ownernickname').html();
            var imgurl=$('#ownerimg').attr('src');
            for(var i in data.result.commentList){
                if(i == 'pictureList'){continue;}
                var ownerComment   = '',
                    userCommentPic = '';

                //评论照片
                if((data.result.commentList[i].pictureList) && (data.result.commentList[i].pictureList.length > 0)){
                    var j              = 0,
                        arr            = data.result.commentList[i].pictureList,
                        userCommentPic = '<ul class="seeBigerPic customerCommentImg">';
                    for(j = 0; j < arr.length; j++ ){
                        userCommentPic += '<img style="width:60px;height:60px;margin:13px 5px 4px 0px" src="' +arr[j].url+ '?pt=1&st=large" data-src="' +arr[j].url+ '" alt="">';
                    };
                    userCommentPic += '</ul>';
                };
                //评论照片

                if(data.result.commentList[i].hasOwnerComment == 1){
                    ownerComment = '<div class="col-md-12 col-lg-12 comment-reply">\n\
                                                <div class="col-md-11 col-lg-11 padding0">\n\
                                                    <div class="col-md-12 col-lg-12 padding0 comment-infor">\n\
                                                        【房东回复】\n\
                                                    </div>\n\
                                                    <div class="col-md-12 col-lg-12 padding0 comment-con">\n\
                                                        <p>'+data.result.commentList[i].ownerComment+'</p>\n\
                                                    </div>\n\
                                                </div>\n\
                                            </div>';
                }

                var userImg=publicMethods.getUserHeadUrl(data.result.commentList[i].faceUrl,'small');
                var createdAt = data.result.commentList[i].createdAt;

                var currentLanguage = $.i18n.prop(publicMethods.languageArr[$.cookie('language')||'zh'] || 'ba61401f60eaab451e8cd2e739aa7a03');
                var translateBtn = data.result.commentList[i].translateButton ? '<button class="translate-btn translateBtn mT10 mB0" data-subject="COMMENT" data-child="CONTENT-0" data-id="'+data.result.commentList[i].id+'">'+$.i18n.prop('ba61401f60eaab451e8cd2e739aa7a08')+' '+currentLanguage+'</button>' : '';
                str +='<div class="row marginT32 comment-box padding0 translateWrap"><div class="col-md-12 col-lg-12 paddingL0 paddingR0 comment-list">\n\
                                    <div class="col-md-1 col-lg-1 padding0">\n\
                                        <div class="media-photo media-round mT30">\n\
                                                <img alt="'+data.result.commentList[i].nickName+'" src="' + userImg + '" title="'+data.result.commentList[i].nickName+'" onerror="this.src=\'/images/user_pic-225x225.png\'">\n\
                                        </div>\n\
                                    </div>\n\
                                    <div class="col-md-11 col-lg-11 padding0 paddingL18">\n\
                                    <div class="col-md-12 col-lg-12 padding0 comment-wrap">\n\
                                        <div class="col-md-12 col-lg-12 padding0 comment-infor">\n\
                                            <div class="col-md-2 col-lg-2 padding0 ellipsis">'+data.result.commentList[i].nickName+'</div>\n\
                                            <div class="col-md-10 col-lg-10">'+createdAt.substring(0,4)+'-'+createdAt.substring(5,7)+'-'+createdAt.substring(8,10)+ ' ' + $.i18n.prop('521221622c87df4d119042eb96159399')+'</div>\n\
                                        </div>\n\
                                        <div class="col-md-12 col-lg-12 padding0 comment-con">\n\
                                            <p class="translateDisplay">'+data.result.commentList[i].content+'</p>\n\
                                            '+translateBtn+'\n\
                                        </div>\n\
                                        '+userCommentPic+'\n\
                                        '+ownerComment+'\n\
                                    </div>\n\
                                    </div>\n\
                                </div><div class="clearfx"></div>\n\
                            </div>';
            }
            $('.comment').html(str);
            //首次进来下拉出现评价
            if(refresh){
                $('.comment').slideDown("slow");
                if(data.result.count){
                    $('.datashow').html('('+data.result.count+')');
                    $('#firstComment').show();
                    $('.nocommon').hide();
                    $('.hascommon,.comment-page').show();

                }else{
                    //$('.datashow').html('0条评价');
                    $('.comment-count.comment-count').hide();
                    $('.nocommon').show();
                    $('.hascommon,.comment-page').hide();
                    $('.comment-star').hide();
                }
                if(data.result.count>0){
                    $('.comment-level-small').show();
                    $('.comment-status').children('.comment-level').removeClass('hide');
                }else{
                    $('.comment-status').show();
                }

            }
            if(data.result.count){
                if(data.result.count<=10){
                    $('.pagination-responsive').addClass('hide');
                }else{
                    var str = setPageForSearch(page,range.pageSize,data.result.count,'details');
                    $('.pagination-responsive').html(str);
                }
            }else{
                $('.pagination-responsive').addClass('hide');
            }
        }
    });
}

function getPosition(obj,parentClass,resultName){
    var tempparent= obj;
    var top=0;left=0;
    while(!tempparent.hasClass(parentClass))
    {
        top+=tempparent.position().top;
        left+=tempparent.position().left;
        tempparent=tempparent.parent();
    }
    $('[name='+resultName+']').attr('pTop',top).attr('pLeft',left);


}


/*
 * 分析订单时间(预订) jiph 160701
 * for templates/onehome/room/details.html
 */
function analyzeOrder(start, end) {
    try{
	    var houseId = $('#houseId').val();
        var checkins = $('.checkins').val();
        var checkouts = $('.checkouts').val();
        if (start && end) {
            checkins = start;
            checkouts = end;
        }
        if(!checkins || !checkouts){
            return;
        }

        var userId=$.trim($('[name=userId]').val());
        var ownerId=$.trim($('[name=ownerId]').val());

        if(userId==ownerId)
        {
            $('#book_it_disabled_message').html($.i18n.prop('4301d76e07597cfdd1c745cbceee1ad2')).removeClass('hide').parent().show();
            return;
        }

        var $messagebook=$('#book_it_disabled_message');
        if($messagebook.attr('errortype')!='2')
        {
            $messagebook.html('');
            $messagebook.addClass('hide').parent().hide();
        }
        else
            return;

	    var extraAfter = $('input[name=extraAfter]').val();//额外起算人数
	    var number_of_guest =  $('.defineselectinput').attr('numvalue');//选择人数
	    var currency_symbol = $.cookie("currency_symbol");

	    /*20180507 以前是前端算预览价格 改为从后端取*/
        /*var minNights = $('.minNights').html(); //最短入住天数
        var price_amount_num = $('input[name=price_amount_num]').val();//单价
        var cleanFee = Math.round($('input[name=cleanFee]').val());//清洁费
        var extraPerGuest = $('input[name=extraPerGuest]').val();//额外人员费用
        var hasWeekendPrice = Math.round($('input[name=hasWeekendPrice]').val());//判断是否设置周末价格
        var weekendPrice = $('input[name=weekendPrice]').val();//周末价格
        var depositWay = $('input[name=depositWay]').val();//周末价格
        var priceDeposit = Math.round($('input[name=priceDeposit]').val());//线上押金

        price_amount_num = parseInt(price_amount_num);
        //获取单独设置的日期
        var houseCalendar = $('input[name=dynamicPrice]').val();
        var calendar = JSON.parse(houseCalendar); //特殊价格
        var timeList = listTime(checkins, checkouts); //用户选择的日期范围
        var initialPrice = 0;
        var priceList = [];
        for (var i = 0; i < timeList.length; i++) {

            //判断是否有周末价格
            var date = new Date(timeList[i].substring(0, 4) + '-' + timeList[i].substring(4, 6) + '-' + timeList[i].substring(6, 8)); //设定当前月日期
            var week = false;
            if ((date.getDay() == 5 || date.getDay() == 6) && hasWeekendPrice == '1') {
                week = true;
            }
            //有特殊价格和没有特殊价格的情况进行分析
            if (calendar.length == 0) {
                if (week) {
                    //有周末价格的情况下
                    initialPrice = initialPrice + Math.round(weekendPrice);
                    priceList = checkPrice(currency_symbol, Math.round(weekendPrice), priceList);
                } else {
                    //没有周末价格的情况下
                    initialPrice = initialPrice + Math.round(price_amount_num);
                    priceList = checkPrice(currency_symbol, Math.round(price_amount_num), priceList);
                }
            } else {
                //有特殊价格的情况下
                var boo = true;
                for (var j = 0; j < calendar.length; j++) {
                    if (calendar[j].chooseDate.indexOf(timeList[i]) >= 0) {
                        initialPrice = initialPrice + Math.round(calendar[j].price);
                        priceList = checkPrice(currency_symbol, Math.round(calendar[j].price), priceList);
                        boo = false;
                        break;
                    }
                }
                if (boo) {
                    if (week) {
                        //有周末价格的情况下
                        initialPrice = initialPrice + Math.round(weekendPrice);
                        priceList = checkPrice(currency_symbol, Math.round(weekendPrice), priceList);
                    } else {
                        initialPrice = initialPrice + price_amount_num;
                        priceList = checkPrice(currency_symbol, Math.round(price_amount_num), priceList);
                    }
                }
            }
        }
        var priceLists = '';
        for (var i = 0; i < priceList.length; i++) {
            if (i % 2 == 0) {
                priceLists = priceLists + '<tr><td>' + priceList[i].priceName + '</td><td>' + priceList[i].totalPrice + '</td></tr>';
            } else {
                priceLists = priceLists + '<tr><td>' + priceList[i].priceName + '</td><td>' + priceList[i].totalPrice + '</td></tr>';
            }
        }

        var oDate1 = new Date(checkins);
        var oDate2 = new Date(checkouts);
        var iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);    //把相差的毫秒数转换为天数

        if (checkins != '' && checkouts != '') {
            //判断折扣
            discount = 0;
            var disTR = 0, extraPrice = 0;
            //计算额外人员费用
            if ((parseInt(number_of_guest) > parseInt(extraAfter)) && (parseInt(extraAfter) > 0) && (parseInt(extraPerGuest) > 0)) {
                extraPrice = Math.round((number_of_guest - extraAfter) * extraPerGuest * iDays);
                initialPrice = initialPrice + extraPrice;
                disTR++;
                var chaoc = number_of_guest - extraAfter;
                if (extraPrice) {
                    priceLists = priceLists + $.i18n.prop('a4210f3a79c8857ae496c7b1aef0b938') + chaoc + $.i18n.prop('2b0f70caba1e492e88428b6f5e72cf0d') + currency_symbol + extraPrice + '</td></tr>';
                }
            }
            //计算清洁费
            if (cleanFee > 0) {
                disTR++;
                if ((priceList.length + disTR) % 2 == 0) {
                    priceLists = priceLists + $.i18n.prop('50c754c205dd9b0ff2d076dc978ae0b7') + currency_symbol + cleanFee + '</td></tr>';
                } else {
                    priceLists = priceLists + $.i18n.prop('49878b4b5d179e6b72309f9c2b5d0867') + currency_symbol + cleanFee + '</td></tr>';
                }
            }
            if (iDays >= 7 && iDays < 30) {
                //7天的折扣率
                var discount7day = $('input[name=discount7day]').attr('value');
                if (discount7day > 0 && discount7day < 1) {
                    disTR++;
                    var zk = parseFloat(discount7day);
                    var discount = Math.round(initialPrice * zk);
                    if ((priceList.length + disTR) % 2 == 0) {
                        priceLists = priceLists + $.i18n.prop('45b3d948d2fbded9886eac267fcbe234') + currency_symbol + discount + '</td></tr>';
                    } else {
                        priceLists = priceLists + $.i18n.prop('45b3d948d2fbded9886eac267fcbe234') + currency_symbol + discount + '</td></tr>';
                    }
                }
            } else if (iDays >= 30) {
                //30天的折扣率
                var discount30day = $('input[name=discount30day]').attr('value');
                if (discount30day > 0 && discount30day < 1) {
                    disTR++;
                    var zk = parseFloat(discount30day);
                    //计算折扣费用
                    discount = Math.round(initialPrice * zk);
                    if ((priceList.length + disTR) % 2 == 0) {
                        priceLists = priceLists + $.i18n.prop('45b3d948d2fbded9886eac267fcbe234') + currency_symbol + discount + '</td></tr>';
                    } else {
                        priceLists = priceLists + $.i18n.prop('8ccb34bc1f4bc1c98c440f56ccc9656f') + currency_symbol + discount + '</td></tr>';
                    }
                }
            }
            // 线上押金
            if(depositWay == 1){
                priceLists = priceLists + $.i18n.prop('2b26a7b9fe886ad4fa948dbcb30c1892') + currency_symbol + priceDeposit + '</td></tr>';
            }else{
                priceDeposit = 0;
            }
            //最后结算总价
            var allPrice = Math.round(initialPrice - discount + cleanFee + priceDeposit);

            if ((priceList.length + disTR) % 2 == 0) {
                priceLists = priceLists + $.i18n.prop('39e5e64078a7bd1f68f84325e400f6e1') + currency_symbol + allPrice + '</td></tr>';
            } else {
                priceLists = priceLists + $.i18n.prop('e0f7c306c1e906f5b15ab342f6ec3911') + currency_symbol + allPrice + '</td></tr>';
            }
            //隐藏所有判断

            //展示价格详情
            $('.priceList-box').removeClass('hide');
            $('.priceList').html(priceLists);
        }*/

	    $('#priceBox').append('<span class="saving"><img src="/images/publish/uploading.png"/></span>');

	    getUsableCoupon(houseId,number_of_guest,checkins,checkouts,[],function(data){
            if(data.status.status_code == 0){
                var priceInfo = data.result.priceInfo;
                var priceLists = '';
	            var allPrice = Math.round(priceInfo.totalPrice);
                for(var i in priceInfo.priceList){
                    priceLists += '<tr><td>' + priceInfo.priceList[i].priceCount + '</td><td>' + priceInfo.priceList[i].price + '</td></tr>'
                }
                if(priceInfo.extraFee && priceInfo.extraFee!=0){
                    priceLists += '<tr><td>' + $.i18n.prop('a4210f3a79c8857ae496c7b1aef0b938') + (number_of_guest-extraAfter) + $.i18n.prop('2b0f70caba1e492e88428b6f5e72cf0d') + '</td><td>' + currency_symbol + priceInfo.extraFee + '</td></tr>';
                }
                if(priceInfo.cleanFee && priceInfo.cleanFee!=0){
                    priceLists += '<tr><td>' + $.i18n.prop('50c754c205dd9b0ff2d076dc978ae0b7') + '</td><td>' + currency_symbol + priceInfo.cleanFee + '</td></tr>';
                }
                if(priceInfo.discount && priceInfo.discount!=0){
                    priceLists += '<tr><td>' + $.i18n.prop('45b3d948d2fbded9886eac267fcbe234') + '</td><td>-' + currency_symbol + priceInfo.discount + '</td></tr>';
                }
                if(priceInfo.coupon && priceInfo.coupon!=0){
                    priceLists += '<tr><td>' + $.i18n.prop('f309c96a49cb3b11886076780afbdac8') + '</td><td>-' + currency_symbol + priceInfo.coupon + '</td></tr>';
                }
                if(priceInfo.priceDeposit && priceInfo.priceDeposit!=0){
                    priceLists += '<tr ><td>' + $.i18n.prop('2b26a7b9fe886ad4fa948dbcb30c1892') + '</td><td>' + currency_symbol + priceInfo.priceDeposit + '</td></tr>';
                }
                priceLists += '<tr ><td class="totcalpriceword">' + $.i18n.prop('39e5e64078a7bd1f68f84325e400f6e1') + '</td><td class="totalpricenumspan">' + currency_symbol + allPrice + '</td></tr>';


	            //展示价格详情
	            if($('[name=sFromId]').val() == 210){
		            $('#priceTips').show();
	            }
	            $('.priceList').html(priceLists);
	            $('.priceList-box').removeClass('hide');
            }else{
                //清空价格列表并显示错误信息
	            $('.priceList').html('');
	            $('.priceList-box').addClass('hide');
	            $('#book_it_disabled_message').html('<span>'+data.status.status_reason+'</span>').removeClass('hide').parent().show();
            }
		    $('#priceBox').find('.saving').remove();
        },function(data){
            alert(data.status_reason);
		    $('#priceBox').find('.saving').remove();
        })
    }
    catch(e){

    }

}



//放大图片切换动作
function maxdetailImgChangeAction(move){
    var box = $('.smallimglist');
    var tab1 = $('.smallimglist .smalllistul');
    var left = tab1.css('left').replace('px', '')
    var actIndex = tab1.children('img.action').index();
    var totalNum = tab1.children('img').length;

    var smallimglistwidth=$('.smallimglist').width();
    var divsor=6;
    if(parseInt(smallimglistwidth)==1070)
        divsor=7;

    if(totalNum==1)
        return;
    if(move == 'prev'){
        if(parseInt(left)<-1){
            maxchangeBigImg(actIndex-1);
            left = parseInt(left) + 154;


            if(totalNum>divsor)
                tab1.stop(true).animate({left: left+"px"}, 10);
            tab1.children('img').eq(actIndex).removeClass('action');
            tab1.children('img').eq(actIndex-1).addClass('action');
        }else{
            if(actIndex > 0){
                //var smallimglistwidth=$('.smallimglist').width();
                //var divsor=6;
                //if(parseInt(smallimglistwidth)==1070)
                //    divsor=7;
                //
                //var lengthstr= tab1.children('img').length;
                //var left=-((lengthstr-divsor)*154);

                maxchangeBigImg(actIndex-1);
                tab1.children('img').eq(actIndex).removeClass('action');
                tab1.children('img').eq(actIndex-1).addClass('action');
            }
            if(actIndex==0){


                var lengthstr= tab1.children('img').length;
                var left=-((lengthstr-divsor)*154);
                actIndex=lengthstr-1;
                maxchangeBigImg(actIndex);
                //left = left;
                if(totalNum>divsor)
                    tab1.stop(true).animate({left: left+"px"}, 10);
                tab1.children('img').eq(0).removeClass('action');
                tab1.children('img').eq(actIndex).addClass('action');
            }

        }

    }else{
        if(parseInt(tab1.width())+parseInt(left)-parseInt(box.width())>10){
            maxchangeBigImg(actIndex+1);
            left = parseInt(left) - 154;
            if(totalNum>divsor)
                tab1.stop(true).animate({left: left+"px"}, 10);
            tab1.children('img').eq(actIndex).removeClass('action');
            tab1.children('img').eq(actIndex+1).addClass('action');
        }else{
            if(actIndex < totalNum-1){
                maxchangeBigImg(actIndex+1);
                tab1.children('img').eq(actIndex).removeClass('action');
                tab1.children('img').eq(actIndex+1).addClass('action');
            }else{
                maxchangeBigImg(0);

                if(totalNum>divsor)
                    tab1.stop(true).animate({left: "0px"}, 10);
                tab1.children('img').eq(actIndex).removeClass('action');
                tab1.children('img').eq(0).addClass('action');
            }
        }
    }
}
//切换图片的时候的根据图片大小调整图片位置
function maxchangeBigImg(index){
    try{
        $('.indexbox .pageindex').html(index+1);
        var tab1 = $('.smallimglist .smalllistul');
        var url = tab1.children('img').eq(index).attr('data-url');
        if(url)
            url=url.split('_1')[0];

        var $description = $('.descriptionbox .description').eq(index);
        if($description.html()){
            $description.show().siblings().hide();
        }else{
            $description.siblings().hide();
        }
        var $bigerimg=$('.biger-imgbox img');
        if(ieflag){//如果是ie浏览器
            $bigerimg.attr('src',publicMethods.pathSetting.hosueImgUrl);
            $bigerimg.attr('src',url+'_1_xxlarge.jpg');
        }
        else{
            $bigerimg.attr('src',"");
            $bigerimg.attr('src',url+'_1_xxlarge.jpg');
        }

        var container = $('.big-img-top');
        var w_x = container.width();
        var w_y = container.height();
        var src = $('.smallimglist .smalllistul').children('img').eq(index).attr('src');
        var theImage = new Image();
        theImage.src = src;
        theImage.onload = function(){
            //原始宽度
            var img_width = this.width;
            //原始高度
            var img_height = this.height
            if((img_width/img_height) - (w_x/w_y) > 0.2){
                //伸长后的高度
                var fu_height = w_x*img_height/img_width;
                //求偏移量
                var offset_y = (fu_height-w_y)/2;
                container.children('img').css('width','100%');
                container.children('img').css('height',fu_height+'px');
                container.children('img').css('margin-top',-offset_y+'px');
                container.children('img').css('margin-left','0px');
            }else if((img_width/img_height) - (w_x/w_y) < -0.2){
                //伸长后的高度
                var fu_width = w_y*img_width/img_height;
                //求偏移量
                var offset_x = (fu_width-w_x)/2;
                container.children('img').css('height','100%');
                container.children('img').css('width',fu_width+'px');
                container.children('img').css('margin-left',-offset_x+'px');
                container.children('img').css('margin-top','0px');

            }else{
                container.children('img').css('height','100%');
                container.children('img').css('width','100%');
                container.children('img').css('margin-top','0px');
                container.children('img').css('margin-left','0px');
            }

        }
        $('#biger-largeimg').load(function(){
            var $this=$(this);
            $('.indexbox').width($this.width()).css('margin-left',$this.css('marginLeft'));

        });

    }
    catch(e){}

}
// copy Nav‘登录’click事件
function loginLink_Header(){
    var host = window.location.host;
    var href = window.location.href;
    var his_ex = href.indexOf(host);
    var history = href.substring(his_ex+host.length,href.length);
    if(history.indexOf('/forget/p_forget')>=0 || history.indexOf('/login/p_login') >= 0 || history.indexOf('/register/p_register') >= 0){
        window.location.href='/login/p_login';
    }else{
        window.location.href='/login/p_login?history='+history;
    }
}






